Conditions | 36 |
Paths | 3 |
Total Lines | 58 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like stringFuncs.toKeywords often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | /** global: UB */ |
||
27 | }, |
||
28 | |||
29 | restrictToLettersDigits: function(spacesOk = false){ |
||
30 | var str = this; |
||
31 | /* INPUT ~!@#$%&* {:'\"<>[ © € Characters 2007 |
||
32 | * OUTPUT Characters2007 */ |
||
33 | if (str == null) { |
||
34 | return null; |
||
35 | } |
||
36 | var result = []; |
||
37 | for (var a = 0;a<str.length;a++){ |
||
38 | var char = str.charCodeAt(a); |
||
39 | if ((char >= UB.charCodes._0 && char <= UB.charCodes._9) || |
||
40 | (char >= UB.charCodes.A && char <= UB.charCodes.Z) || |
||
41 | (char >= UB.charCodes.a && char <= UB.charCodes.z) || |
||
42 | (spacesOk && char == UB.charCodes.Space)) { |
||
43 | result.push(str.charAt(a)); |
||
44 | } |
||
45 | } |
||
46 | return result.join(""); |
||
47 | }, |
||
48 | restrictToLetters: function(spacesOk = false){ |
||
49 | var str = this; |
||
50 | /* INPUT ~!@#$%&* {:'\"<>[ © € Characters 2007 |
||
51 | * OUTPUT Characters */ |
||
52 | if (str == null) { |
||
53 | return null; |
||
54 | } |
||
55 | var result = []; |
||
56 | for (var a = 0;a<str.length;a++){ |
||
57 | var char = str.charCodeAt(a); |
||
58 | if ((char >= UB.charCodes.A && char <= UB.charCodes.Z) || |
||
59 | (char >= UB.charCodes.a && char <= UB.charCodes.z) || |
||
60 | (spacesOk && char == UB.charCodes.Space)) { |
||
61 | result.push(str.charAt(a)); |
||
62 | } |
||
63 | } |
||
64 | return result.join(""); |
||
65 | }, |
||
66 | restrictToDigits: function(spacesOk = false){ |
||
67 | var str = this; |
||
68 | /* INPUT ~!@#$%&* {:'\"<>[ © € Characters 2007 |
||
69 | * OUTPUT 2007 */ |
||
70 | if (str == null) { |
||
71 | return null; |
||
72 | } |
||
73 | var result = []; |
||
74 | for (var a = 0;a<str.length;a++){ |
||
75 | var char = str.charCodeAt(a); |
||
76 | if ((char >= UB.charCodes._0 && char <= UB.charCodes._9) || |
||
77 | (spacesOk && char == UB.charCodes.Space)) { |
||
78 | result.push(str.charAt(a)); |
||
79 | } |
||
80 | } |
||
81 | return result.join(""); |
||
82 | }, |
||
83 | restrictToFilename: function(replaceWith = "_"){ |
||
84 | var path = this; |
||
85 | return path.ensureValidFilename(replaceWith); |
||
125 | UB.registerFuncs(String.prototype, stringFuncs); |